package cz.cvut.fel.loader;

import cz.cvut.fel.email.Email;


public abstract class Persister extends Thread {
	protected String server;
	protected Integer port;
	
	public Persister(String server, Integer port) {
		super();
		this.server = server;
		this.port = port;
	}
	
	protected static String parseServer(String server) {
		if (server.contains(":"))
			return server.substring(0,server.lastIndexOf(":"));

		return server;
	}
	protected static Integer parsePort(String server) {
		if (server.contains(":"))
			return Integer.parseInt(server.substring(server.lastIndexOf(":")+1));

		return 0;
	}
	
	public abstract void connect() throws Exception;
	
	//public abstract void store(byte[] data) throws Exception;
	
	public abstract void disconnect();

	public abstract void store(Email email) throws Exception;
	
	public abstract byte[] readBytes() throws Exception;
}
